package com.example.controller;

import com.example.pojo.*;
import com.example.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: Sun
 * @Date: 2025/9/22 - 09 - 22 - 10:22
 * @Description: com.example.controller
 */
@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public Result list(ClazzQueryParam clazzQueryParam){
        log.info("查询班级列表");
        PageResult<Clazz> pageResult = clazzService.list(clazzQueryParam);
        return Result.success(pageResult);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除班级");
        clazzService.deleteById(id);
        return Result.success();

    }
    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        log.info("新增班级");
        clazzService.save(clazz);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){


        log.info("根据id查询班级");
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);}
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级");
        clazzService.updateById(clazz);
        return Result.success();
    }
//    @GetMapping("emps/list")
//    public Result listAll(Emp emp){
//        log.info("查询班级列表");
//        List<Emp> list = clazzService.listAll(emp);
//        return Result.success(list);
//    }
    @GetMapping("/list")
    public Result listAll(){
        log.info("查询班级列表");
        List<Clazz> list = clazzService.listAll();
        return Result.success(list);


}
}
